package org.upfrost.util;

import java.io.Serializable;

public class Pair<A,B> implements Serializable
{
	private A m_first  = null;
	private B m_second = null;
	
	public Pair()
	{
	}

	public Pair(Pair<A,B> p)
	{
		m_first = p.m_first;
		m_second = p.m_second;
	}
	
	public Pair(A a, B b)
	{
		m_first = a;
		m_second = b;
	}
	
	public void setFirst(A a)
	{
		m_first = a;
	}
	
	public A getFirst()
	{
		return m_first;
	}
	
	public void setSecond(B b)
	{
		m_second = b;
	}
	
	public B getSecond()
	{
		return m_second;
	}
	
	public String toString()
	{
		return "("+m_first+","+m_second+")";
	}

	@Override
	public int hashCode() {
		int firstHash = (m_first==null)?0:m_first.hashCode();
		int secondHash = (m_second==null)?0:m_second.hashCode();
		return firstHash * secondHash;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		
		if (obj instanceof Pair)
		{
			boolean resfirst = false;
			boolean ressecond = false;
			
			Pair other = (Pair)obj;
			if (this.m_first == null && other.m_first == null)
				resfirst = true;
			else if (this.m_first != null && this.m_first.equals(other.m_first))
				resfirst = true;
			
			if (this.m_second == null && other.m_second == null)
				ressecond = true;
			else if (this.m_second != null && this.m_second.equals(other.m_second))
				ressecond = true;

			return resfirst && ressecond;
		}

		return false;
	}



}
